#include "addnewfeedialog.h"
#include "ui_addnewfeedialog.h"
#include <QSqlQuery>
#include <QMessageBox>
#include <QSqlError>
#include <QString>



addNewFeeDialog::addNewFeeDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::addNewFeeDialog)
{
    ui->setupUi(this);
    ui->courier_company_comboBox->addItem("顺丰");
    ui->courier_company_comboBox->addItem("EMS");
    ui->courier_company_comboBox->addItem("京东");
}

addNewFeeDialog::~addNewFeeDialog()
{
    delete ui;
}

void addNewFeeDialog::on_pushButton_clicked()
{
    QDate record_date=ui->record_dateEdit->date();  //登记日期
    QString courier_company=ui->courier_company_comboBox->currentText();    //快递公司
    QString tracking_number=ui->tracking_number_lineEdit->text();   //快递单号
    QString sender_name=ui->sender_name_lineEdit->text();   //发件人姓名
    QString sender_phone=ui->sender_phone_lineEdit->text();
    QString sender_address=ui->sender_address_lineEdit->text();
    QString recipient_name=ui->recipient_name_lineEdit->text();
    QString recipient_phone=ui->recipient_phone_lineEdit->text();
    QString recipient_address=ui->recipient_address_lineEdit->text();
    QDate delivery_date=ui->delivery_dateEdit->date();
    QString fee=ui->fee_lineEdit->text();
    QDate created_at=ui->created_dateEdit->date();

    QSqlQuery query;
    query.prepare("insert into logisticsfees (record_date,courier_company,tracking_number,"
                  "sender_name,sender_phone,sender_address,recipient_name,recipient_phone,"
                  "recipient_address,delivery_date,fee,created_at) "
                  "values(:record_date,:courier_company,:tracking_number,"
                  ":sender_name,:sender_phone,:sender_address,:recipient_name,:recipient_phone,"
                  ":recipient_address,:delivery_date,:fee,:created_at)");
    query.bindValue(":recor_date",record_date);
    query.bindValue(":courier_company",courier_company);
    query.bindValue(":tracking_number",tracking_number);
    query.bindValue(":sender_name",sender_name);
    query.bindValue(":sender_phone",sender_phone);
    query.bindValue(":sender_address",sender_address);
    query.bindValue(":recipient_name",recipient_name);
    query.bindValue(":recipient_phone",recipient_phone);
    query.bindValue(":recipient_address",recipient_address);
    query.bindValue(":delivery_date",delivery_date);
    query.bindValue(":fee",fee);
    query.bindValue(":created_at",created_at);

    if(!query.exec())
    {
        QMessageBox::critical(this,"提示","新增失败！"+query.lastError().text());
        return;
    }



}

